<template>
  <div class='container'>
    <el-dialog
      title="预览文章"
      :visible="showPreviewDialog"
      width="70%"
      :close-on-click-modal="false"
      @close="closeDialog"
    >
      <div class="previewbox">
        <div class="previewtitle">
          <h2>{{preform.title}}</h2>
          <span>{{ formatDate(preform.createTime) }}</span>
          <span>超级管理员</span>
          <span><i class="el-icon-user"></i></span>
          <span> {{preform.visits}}</span>
        </div>
        <div
          v-html="preform.articleBody"
          class="articleBody"
        ></div>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  name: 'ArticlesPreview',
  props: {
    showPreviewDialog: {
      type: Boolean,
      default: false
    },
    preform: {
      type: Object,
      default: () => {},
      require: true
    }
  },
  methods: {
    getPreviewForm () {},
    // 关闭弹层
    closeDialog () {
      this.$emit('update:showPreviewDialog', false)
      this.preform.title = ''
      this.preform.createTime = ''
      this.preform.articleBody = ''
      this.preform.videoURL = ''
    },
    // 时间格式转换
    formatDate (date) {
      return dayjs(date).format('YYYY-MM-DD HH:mm:ss')
    }
  }
}
</script>

<style scoped lang='scss'>
.articleBody {
  color: #606266;
  font-size: 14px;
  word-break: break-all;
  background: #f5f5f5;
  padding: 10px;
}

.previewtitle {
  border-bottom: 1px dashed #ccc;
  padding-bottom: 10px;
}
span {
  margin-left: 10px;
  margin-top: 10px;
}
</style>
